from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-06 14:06:18.724194
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 06, Feb, 2022
Time: 14:06:23
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.9975
Nobs: 559.000 HQIC: -48.4220
Log likelihood: 6561.29 FPE: 7.11997e-22
AIC: -48.6940 Det(Omega_mle): 6.06979e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351633 0.069258 5.077 0.000
L1.Burgenland 0.106264 0.042113 2.523 0.012
L1.Kärnten -0.110585 0.021882 -5.054 0.000
L1.Niederösterreich 0.193487 0.087537 2.210 0.027
L1.Oberösterreich 0.132333 0.086953 1.522 0.128
L1.Salzburg 0.254393 0.044539 5.712 0.000
L1.Steiermark 0.034547 0.058695 0.589 0.556
L1.Tirol 0.099204 0.047403 2.093 0.036
L1.Vorarlberg -0.071094 0.041901 -1.697 0.090
L1.Wien 0.017260 0.077400 0.223 0.824
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054845 0.149872 0.366 0.714
L1.Burgenland -0.041210 0.091132 -0.452 0.651
L1.Kärnten 0.040727 0.047352 0.860 0.390
L1.Niederösterreich -0.199230 0.189427 -1.052 0.293
L1.Oberösterreich 0.454598 0.188163 2.416 0.016
L1.Salzburg 0.283354 0.096380 2.940 0.003
L1.Steiermark 0.114347 0.127014 0.900 0.368
L1.Tirol 0.306034 0.102579 2.983 0.003
L1.Vorarlberg 0.022891 0.090673 0.252 0.801
L1.Wien -0.026712 0.167491 -0.159 0.873
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.193038 0.035368 5.458 0.000
L1.Burgenland 0.088689 0.021506 4.124 0.000
L1.Kärnten -0.007526 0.011174 -0.674 0.501
L1.Niederösterreich 0.236411 0.044702 5.289 0.000
L1.Oberösterreich 0.170145 0.044404 3.832 0.000
L1.Salzburg 0.039048 0.022744 1.717 0.086
L1.Steiermark 0.025088 0.029973 0.837 0.403
L1.Tirol 0.081413 0.024207 3.363 0.001
L1.Vorarlberg 0.054939 0.021398 2.568 0.010
L1.Wien 0.120526 0.039526 3.049 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120167 0.035376 3.397 0.001
L1.Burgenland 0.043501 0.021511 2.022 0.043
L1.Kärnten -0.013623 0.011177 -1.219 0.223
L1.Niederösterreich 0.168684 0.044712 3.773 0.000
L1.Oberösterreich 0.335006 0.044414 7.543 0.000
L1.Salzburg 0.099731 0.022749 4.384 0.000
L1.Steiermark 0.110168 0.029980 3.675 0.000
L1.Tirol 0.090724 0.024213 3.747 0.000
L1.Vorarlberg 0.061171 0.021402 2.858 0.004
L1.Wien -0.015766 0.039534 -0.399 0.690
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127332 0.066654 1.910 0.056
L1.Burgenland -0.048709 0.040530 -1.202 0.229
L1.Kärnten -0.045518 0.021060 -2.161 0.031
L1.Niederösterreich 0.136845 0.084246 1.624 0.104
L1.Oberösterreich 0.166218 0.083684 1.986 0.047
L1.Salzburg 0.284554 0.042864 6.638 0.000
L1.Steiermark 0.057807 0.056488 1.023 0.306
L1.Tirol 0.156292 0.045621 3.426 0.001
L1.Vorarlberg 0.094731 0.040326 2.349 0.019
L1.Wien 0.073766 0.074491 0.990 0.322
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.081134 0.052022 1.560 0.119
L1.Burgenland 0.024176 0.031633 0.764 0.445
L1.Kärnten 0.053311 0.016436 3.244 0.001
L1.Niederösterreich 0.190971 0.065752 2.904 0.004
L1.Oberösterreich 0.331715 0.065313 5.079 0.000
L1.Salzburg 0.032963 0.033454 0.985 0.324
L1.Steiermark 0.004262 0.044087 0.097 0.923
L1.Tirol 0.119765 0.035606 3.364 0.001
L1.Vorarlberg 0.066267 0.031473 2.106 0.035
L1.Wien 0.097445 0.058137 1.676 0.094
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173541 0.062843 2.762 0.006
L1.Burgenland 0.002539 0.038213 0.066 0.947
L1.Kärnten -0.065917 0.019855 -3.320 0.001
L1.Niederösterreich -0.114384 0.079429 -1.440 0.150
L1.Oberösterreich 0.216033 0.078899 2.738 0.006
L1.Salzburg 0.053575 0.040413 1.326 0.185
L1.Steiermark 0.249235 0.053258 4.680 0.000
L1.Tirol 0.498887 0.043012 11.599 0.000
L1.Vorarlberg 0.065275 0.038020 1.717 0.086
L1.Wien -0.075379 0.070231 -1.073 0.283
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158118 0.069554 2.273 0.023
L1.Burgenland -0.004924 0.042293 -0.116 0.907
L1.Kärnten 0.061636 0.021976 2.805 0.005
L1.Niederösterreich 0.173130 0.087911 1.969 0.049
L1.Oberösterreich -0.063588 0.087324 -0.728 0.466
L1.Salzburg 0.205722 0.044729 4.599 0.000
L1.Steiermark 0.139071 0.058946 2.359 0.018
L1.Tirol 0.057361 0.047606 1.205 0.228
L1.Vorarlberg 0.143665 0.042080 3.414 0.001
L1.Wien 0.133066 0.077731 1.712 0.087
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.395124 0.040633 9.724 0.000
L1.Burgenland -0.003251 0.024708 -0.132 0.895
L1.Kärnten -0.020787 0.012838 -1.619 0.105
L1.Niederösterreich 0.199870 0.051357 3.892 0.000
L1.Oberösterreich 0.238646 0.051015 4.678 0.000
L1.Salzburg 0.034482 0.026130 1.320 0.187
L1.Steiermark -0.018993 0.034436 -0.552 0.581
L1.Tirol 0.088262 0.027811 3.174 0.002
L1.Vorarlberg 0.051943 0.024583 2.113 0.035
L1.Wien 0.038026 0.045410 0.837 0.402
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035298 0.104374 0.168786 0.134345 0.095887 0.080920 0.030337 0.212387
Kärnten 0.035298 1.000000 -0.025204 0.132621 0.046626 0.086050 0.443821 -0.068550 0.092579
Niederösterreich 0.104374 -0.025204 1.000000 0.308685 0.123763 0.267972 0.065484 0.156212 0.280989
Oberösterreich 0.168786 0.132621 0.308685 1.000000 0.216038 0.294312 0.169456 0.134249 0.236690
Salzburg 0.134345 0.046626 0.123763 0.216038 1.000000 0.124775 0.089995 0.104187 0.128585
Steiermark 0.095887 0.086050 0.267972 0.294312 0.124775 1.000000 0.134209 0.106332 0.029729
Tirol 0.080920 0.443821 0.065484 0.169456 0.089995 0.134209 1.000000 0.064601 0.152644
Vorarlberg 0.030337 -0.068550 0.156212 0.134249 0.104187 0.106332 0.064601 1.000000 -0.003479
Wien 0.212387 0.092579 0.280989 0.236690 0.128585 0.029729 0.152644 -0.003479 1.000000